package com.zide.ams.controller;

import com.zide.ams.domain.vo.result.AmsArticleResultVO;
import com.zide.ams.domain.vo.save.AmsArticleSaveVO;
import com.zide.ams.domain.vo.search.AmsArticleSearchVO;
import com.zide.ams.service.IAmsArticleService;
import com.zide.common.core.vo.CommonParamIdVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zide.common.core.domain.PageResult;
import com.zide.common.core.domain.CommonResult;

import java.util.List;

import static com.zide.common.core.domain.CommonResult.getResult;
import static com.zide.common.core.domain.CommonResult.success;

/**
 * 博客文章Controller
 * 
 * @author zide
 * @date 2024-04-29
 */
@Tag(name = "博客文章")
@RestController
@RequestMapping("/ams/article")
public class AmsArticleController {
    @Resource
    private IAmsArticleService amsArticleService;

    @Operation(summary = "查询博客文章列表")
    @GetMapping("/list")
    public CommonResult list(AmsArticleSearchVO searchVO) {

        PageResult<AmsArticleResultVO> list = amsArticleService.searchAmsArticlePageList(searchVO);
        return success(list);
    }

    @Operation(summary = "查询热门文章")
    @GetMapping("/hot")
    public CommonResult searchHotList() {
        List<AmsArticleResultVO> list = amsArticleService.searchHotList();
        return success(list);
    }

    @Operation(summary = "阅读文章")
    @GetMapping(value = "/info/{articleId}")
    public CommonResult readArticle(@PathVariable("articleId") Long articleId) {
        return success(amsArticleService.readArticle(articleId));
    }

    @Operation(summary = "获取博客文章详细信息")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return success(amsArticleService.selectAmsArticleById(id));
    }

    @Operation(summary = "新增博客文章")
    @PostMapping
    public CommonResult add(@RequestBody AmsArticleSaveVO saveVO) {
        return getResult(amsArticleService.saveAmsArticle(saveVO));
    }

    @Operation(summary = "修改博客文章")
    @PutMapping
    public CommonResult edit(@RequestBody AmsArticleSaveVO saveVO){
        return getResult(amsArticleService.updateAmsArticle(saveVO));
    }

    @Operation(summary = "删除博客文章")
	@DeleteMapping
    public CommonResult remove(@RequestBody CommonParamIdVO idVO){
        return getResult(amsArticleService.removeAmsArticleByIds(idVO));
    }
}
